
"""
Example directory with explicit binding of components
"""

# Mark the directory as traversable.
__wsgi_directory__ = True

from whiff import resolver
from whiff import tester

# map in the member directories
import misc
import password

# get the authentication component for password protected files.
#
authenticationFilter = resolver.middlewareFromUrl("authorization/myAuthorization")

# override the default for password module to require username/password authentication
#   Note that the file path "password" is a relative path (not "/password") to allow directory relocation
#
password = resolver.moduleRootApplication("password", password, filter_middleware=authenticationFilter)

import resourceTest
from whiff import gateway

# override resourceTest and allow editting of *.whiff files
passwordgw = gateway.SimplePasswordGateway("myuser", "mypassword")
finder = gateway.FilePatternFinder(resourceTest.__path__[0], settable=True)
passwordgw.registerFinder("source", finder)
# for example the path to "./resourceTest/example.whiff" as a resource is
# ["source", "myuser", "mypassword", "example.whiff"]
resourceTest = resolver.moduleRootApplication("resourceTest", resourceTest, resourceGateway=passwordgw)


events_html = resolver.FileContentApplication(__path__[0]+"/events.html", "text/html")

overview_html = resolver.LazyPageFromFile(__path__[0]+"/overview.html")
overview_html.__doc__ = "overview of directory contents"

text_txt = resolver.FileContentApplication(__path__[0]+"/text.txt", "text/plain")
text_txt.__doc__ = "static text file"

text_html = resolver.LazyPageFromFile(__path__[0]+"/text.txt")
text_html.__doc__ = "template interpretation of text.txt"

test_html = resolver.LazyPageFromFile(__path__[0]+"/test.html")

#capture_html = tester.Capture(text_html, __path__[0]+"/capture.output")
capture_output = resolver.LazyPageFromFile(__path__[0]+"/capture.output")

# map in the WhiffTester middleware (used by capture_output)
WhiffTester = tester.WhiffTester

# publish all *.whiff templates
resolver.publish_templates(__path__[0], globals(), directory_middleware=False)

# this handler captures all requests that are not explicitly overridden in the module
#
#__wsgi__ = resolver.MimeDirectoryWithListing(__path__[0], index_application=overview_html)

